package com.yanq.liancar.activity;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.vondear.rxtool.RxActivityTool;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.base.BaseToolbarActivity;
import com.yanq.liancar.util.LogUtils;
import com.yanq.liancar.util.Utils;

import java.net.IDN;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DelicateCarWashContentActivity extends BaseToolbarActivity {
    @BindView(R.id.ll_jingzhun)
    LinearLayout llJingzhun;
    @BindView(R.id.ll_kuaisu)
    LinearLayout llKuaisu;
    @BindView(R.id.tv_Support_business)
    TextView tvSupportBusiness;
    @BindView(R.id.tv_1)
    TextView tv1;
    @BindView(R.id.view1)
    View view1;
    @BindView(R.id.ll_1)
    LinearLayout ll1;
    @BindView(R.id.tv_2)
    TextView tv2;
    @BindView(R.id.view_2)
    View view2;
    @BindView(R.id.ll_2)
    LinearLayout ll2;

    private String id;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_delicatecarwashconten);
        Utils.setStatusBar(this, true, false);
        ButterKnife.bind(this);

        mTvTitle.setText("特惠洗车服务内容");
        id = getIntent().getExtras().getString("id");
        LogUtils.e("ID=====", id+"");
        if (id!=null){
            tvSupportBusiness.setVisibility(View.GONE);
        }
        tv1.setTextColor(getResources().getColor(R.color.main_color));
        view1.setVisibility(View.VISIBLE);
        view1.setBackgroundColor(getResources().getColor(R.color.main_color));
        tv2.setTextColor(getResources().getColor(R.color.gray));
        view2.setVisibility(View.GONE);
        llJingzhun.setVisibility(View.GONE);
        llKuaisu.setVisibility(View.VISIBLE);
    }

    @OnClick({R.id.ll_1, R.id.ll_2, R.id.tv_Support_business, R.id.tv_pay})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_1:
                tv1.setTextColor(getResources().getColor(R.color.main_color));
                view1.setVisibility(View.VISIBLE);
                view1.setBackgroundColor(getResources().getColor(R.color.main_color));
                tv2.setTextColor(getResources().getColor(R.color.gray));
                view2.setVisibility(View.GONE);
                llJingzhun.setVisibility(View.GONE);
                llKuaisu.setVisibility(View.VISIBLE);
                break;
            case R.id.ll_2:
                tv1.setTextColor(getResources().getColor(R.color.gray));
                view1.setVisibility(View.GONE);
                view2.setBackgroundColor(getResources().getColor(R.color.main_color));
                tv2.setTextColor(getResources().getColor(R.color.main_color));
                view2.setVisibility(View.VISIBLE);
                llJingzhun.setVisibility(View.VISIBLE);
                llKuaisu.setVisibility(View.GONE);
                break;
            case R.id.tv_Support_business://查看支持商户
                Bundle bundle = new Bundle();
                bundle.putInt("type", 1);
                RxActivityTool.skipActivity(this, SmallCDelicateCarWashActivity.class, bundle);
                break;
            case R.id.tv_pay:
                serviceDialog();
                break;
        }
    }

    private void serviceDialog() {
        final Dialog bottomDialog = new Dialog(this);
        View contentView = LayoutInflater.from(this).inflate(R.layout.jingzhixiche_dialog, null);
        bottomDialog.setContentView(contentView);
        TextView tv_name = contentView.findViewById(R.id.tv_title);
        tv_name.setText("选择服务项目");
        final TextView tv_kuaisu = contentView.findViewById(R.id.tv_kuaisu);
        final TextView tv_jingzhun = contentView.findViewById(R.id.tv_jingzhun);
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) contentView.getLayoutParams();
        params.width = getResources().getDisplayMetrics().widthPixels;
        //        params.bottomMargin=40;
        contentView.setLayoutParams(params);
        bottomDialog.getWindow().setGravity(Gravity.BOTTOM);
        bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation2);
        bottomDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        bottomDialog.show();
        tv_kuaisu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_kuaisu.setTextColor(getResources().getColor(R.color.white));
                tv_kuaisu.setBackground(getResources().getDrawable(R.drawable.selector_tv_bg_b));
                tv_jingzhun.setTextColor(getResources().getColor(R.color.main_color));
                tv_jingzhun.setBackground(getResources().getDrawable(R.drawable.selector_tv_bg_a));

                Bundle bundle = new Bundle();
                bundle.putInt("type", 80);
                bundle.putString("id", id);
                bundle.putString("statu", "快速洗车");
                RxActivityTool.skipActivityAndFinish(DelicateCarWashContentActivity.this, BuyStandardCarWashActivity.class, bundle);
            }
        });
        tv_jingzhun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_jingzhun.setTextColor(getResources().getColor(R.color.white));
                tv_jingzhun.setBackground(getResources().getDrawable(R.drawable.selector_tv_bg_b));
                tv_kuaisu.setTextColor(getResources().getColor(R.color.main_color));
                tv_kuaisu.setBackground(getResources().getDrawable(R.drawable.selector_tv_bg_a));

                Bundle bundle = new Bundle();
                bundle.putInt("type", 90);
                bundle.putString("id", id);
                bundle.putString("statu", "精准洗车");
                RxActivityTool.skipActivityAndFinish(DelicateCarWashContentActivity.this, BuyStandardCarWashActivity.class, bundle);
            }
        });
    }
}
